package behavior.command;

import behavior.command.command.IMoveCommand;

import java.util.LinkedList;
import java.util.List;

public class MoveControl {

    private List<IMoveCommand> moveCommand = new LinkedList<>();


    /**
     * 执行
     * @param
     */
    public void move(IMoveCommand moveCommand) {
        this.moveCommand.add(moveCommand);
        moveCommand.execute();
    }

    /**
     * 撤销上一个命令
     */
    public void undo() {
        if (moveCommand!= null &&moveCommand.size() > 0) {
            IMoveCommand iMoveCommand = moveCommand.get(moveCommand.size() - 1);
            iMoveCommand.undo();
            moveCommand.remove(iMoveCommand);
        }

    }

    /**
     * 重做上一个命令
     * @param
     */
    public void back(){
        if (moveCommand!= null && moveCommand.size() > 0) {
            IMoveCommand iMoveCommand = moveCommand.get(moveCommand.size() - 1);
            iMoveCommand.execute();
        }

    }


}
